/**
 * 
 */
package co.fitstart.entity.content;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * 模块
 * 
 * @author Leo
 * @author lute
 */
@Entity
@Table(name="content_module")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class Module {

    @Id
    @GeneratedValue
    private Long id;
    
    /** 模块别称 */
    private String alias;
    
    /** 模块名称 */
    private String name;
    
    private Date createTime;
    
    /** 模块可置顶数 */
    private int hotCount;
    
    @Column(name = "is_display")
    private boolean display;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public Module() {

    }

    /**
     * 
     * @param alias
     * @return
     */
    public boolean matches(String alias) {
        return StringUtils.equalsIgnoreCase(alias, this.alias);
    }
    
    /**
     * toggle display status
     * 
     * @return
     */
    public Module toggleDisplay() {
        this.display = this.display ? false : true;
        return this;
    }
    
    /**
     * disable module
     * 
     * @return
     */
    public Module disable() {
        this.disabled = true;
        return this;
    }
    
    /**
     * initialize entity
     * 
     * @return
     */
    public Module initialize() {
        this.createTime = new Date();
        this.disabled = false;
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the alias
     */
    public String getAlias() {
        return alias;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the hotCount
     */
    public int getHotCount() {
        return hotCount;
    }

    /**
     * @return the display
     */
    public boolean isDisplay() {
        return display;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param alias the alias to set
     */
    public void setAlias(String alias) {
        this.alias = alias;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param hotCount the hotCount to set
     */
    public void setHotCount(int hotCount) {
        this.hotCount = hotCount;
    }

    /**
     * @param display the display to set
     */
    public void setDisplay(boolean display) {
        this.display = display;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

}
